package qreporting;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;

import com.google.gdata.data.docs.DocumentListEntry;

@SuppressWarnings("serial")
public class QreportingServlet extends HttpServlet {
	//****************************************
	// FILL YOUR DATA:
	//****************************************
	static String domain = "rojoyazul.com";
	static String userLogin = "fran";
	static String userPassword = "elpassword";
	static String spreadsheetName = "Formulario de prueba";
	static String docName = "Qualification Doc";
	static String css = "";
	static int spreadsheet_line = 0;

	//****************************************
	// DATA COMPOSED AND FIX
	//****************************************
	static String userEmail = userLogin+"@"+domain;
	static String ssFeedURL =   "https://spreadsheets.google.com/feeds/spreadsheets/private/full";
	static String docsFeedURL = "https://docs.google.com/feeds/default/private/full/";


	static String html_begining =
		"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
		"<HTML>" +
		"<HEAD>" +
		"<TITLE>Google doc</TITLE>" +
		//"<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"" + css + "\"/>" +
		
		"<STYLE type=\"text/css\">" + 
		"H1 {color:#0066FF; font-size:35px; font-family:Garamond,Serif;}" +
		"TABLE,TH {border:1px solid black;}" +	
		"TD {padding:15px;}" +
		"</STYLE>" +

		"</HEAD>" +
		"<BODY>\n" +
		"<H1>Qualification Form</H1>\n";
	static String html_end = 
		"</BODY>"+ 
		"</HTML>";
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/html");
		PrintWriter out = resp.getWriter();
	
		//resp.getWriter().println("Hello, world");
		//Spreadsheet2Doc sp2doc = new Spreadsheet2Doc();
		
		String html = "";
		
		html = html + html_begining;		
		html = html + Spreadsheet2Doc.getSpreadSheetInfo(spreadsheetName);
		html = html + html_end;
		out.println("hey ho, there we go!");
		DocumentListEntry dlEntry = null;		
		dlEntry = Spreadsheet2Doc.createNewDocument(docName, html);

		//listSpreadsheets();
		out.println("HTML CODE: \n" + html);
	}
}
